package com.qidianit.mes.pro.converts;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ Description:
 * @ Author: 戴着假发的程序员
 * @ Date: 2025/9/19 - 9:29
 */
@Component// 将这个convert注册在Spring中
public class DateConvert implements Converter<String, Date> {

    @Value("${DATE_CONVERT_PATTERN}")
    private String dateConvertPattern;

    @Override
    public Date convert(String source) {
        try {
            return new SimpleDateFormat(dateConvertPattern).parse(source);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
